package com.sixth.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.BacklightcolorDao;
import com.sixth.entity.Backlightcolor;
import com.sixth.entity.Keycap;
import com.sixth.service.BackLightColorService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project01
 * @description:
 * @author: 老魏
 * @create: 2021-12-27 09:09
 **/
@Service("/backLightColorService")
public class BackLightColorServiceImpl implements BackLightColorService {
    @Autowired
    private BacklightcolorDao backlightcolorDao;

    public CommonResult findAllBackLightColor(){
        List<Backlightcolor> list = backlightcolorDao.selectAllBackLightColor();
        return new CommonResult(0,"",list);
    }
    public CommonResult deleteBackLightColor(Integer backlightcolorid){
        int  row = backlightcolorDao.deleteByPrimaryKey(backlightcolorid);
        if (row>0){
            return new CommonResult(2000,"删除成功",null);
        }else {
            return new CommonResult(5000,"删除失败",null);
        }
    }
    public  CommonResult  addBackLightColor(Backlightcolor backlightcolor){
        int  row = backlightcolorDao.insert(backlightcolor);
        if (row>0){
            return new CommonResult(2000,"新增成功",null);
        }else {
            return new CommonResult(5000,"新增失败",null);
        }
    }

    public  CommonResult  updateBackLightColor(Backlightcolor backlightcolor){
        int  row = backlightcolorDao.updateByPrimaryKey(backlightcolor);
        if (row>0){
            return new CommonResult(2000,"新增成功",null);
        }else {
            return new CommonResult(5000,"新增失败",null);
        }
    }

    public TableLayUi findlightCondition (int page, int limit){
        PageHelper.startPage(page,limit);
        List<Backlightcolor> Backlightcolors= backlightcolorDao.selectlightCondition();
        PageInfo<Backlightcolor> pageInfo= new PageInfo<Backlightcolor>(Backlightcolors);
        return new  TableLayUi(0,"",pageInfo.getTotal(),pageInfo.getList());
    }
}
